package com.gs.weather.dao;

import com.gs.weather.dao.mapper.DisasterSubtypeMapper;
import com.gs.weather.entity.DisasterSubtype;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/21 0021
 */
@Repository
public class DisasterSubtypeDao {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    DisasterSubtypeMapper mapper;

    //添加灾害子类型
    public Integer addDisasterSubtype(DisasterSubtype disasterSubtype) {
        try {
            mapper.addDisasterSubtype(disasterSubtype);
            return disasterSubtype.getId();
        } catch (Exception e) {
            logger.info("addDisasterSubtype失败->{}", e.getMessage());
            return null;
        }
    }

    //更新灾害类型
    public void updateDisasterSubtype(DisasterSubtype disasterSubtype) {
        try {
            mapper.updateDisasterSubtype(disasterSubtype);
        } catch (Exception e) {
            logger.info("updateDisasterSubtype失败->{}", e.getMessage());
        }
    }

    //根据灾害父类型id查询所有灾害子类型（含强度）
    public List<DisasterSubtype> queryDisasterSubtypeByDisasterTypeId(int id) {
        try {
            List<DisasterSubtype> disasterSubtypes = mapper.queryDisasterSubtypeByDisasterTypeId(id);
            return disasterSubtypes;
        } catch (Exception e) {
            logger.info("queryDisasterSubtypeByDisasterTypeId失败->{}", e.getMessage());
            return null;
        }
    }

    //删除灾害子类型
    public void deleteDisasterSubtype(int id) {
        try {
            mapper.deleteDisasterSubtype(id);
        } catch (Exception e) {
            logger.info("deleteDisasterSubtype失败->{}", e.getMessage());
        }
    }

    //查询灾害子类型（含强度）
    /*public List<DisasterSubtype> queryDisasterSubtypeById(int id) {
        return null;
    }*/

    //根据id删除所有子类型的灾害强度
    public void deleteStrengthByDisasterSubtypeId(int id) {

    }
}
